<?php
    $isOwner = $this->session->userdata('user_id') == $oRaoVat->getUserId()?true:false;
    $screen_title = $action=='update'?'Cập nhật':'Thêm mới';
?>

<div class="row">
    <div class="col-md-7 col-xs-12 mgt15">
        <h1 class="pull-left" style="margin-top:0;">
            <?php echo $screen_title; ?>
            <small><?php echo $oRaoVat->getTitle(); ?></small>
        </h1>
    </div>

    <div class="col-md-5 col-xs-12 mgt15">
        <a class="btn btn-default pull-right" href="<?php echo admin_page_url(RAOVAT_SLUG); ?>">
            <i class="glyphicon glyphicon-share-alt"></i> Trở về
        </a>
        <?php if($action=='update') { ?>
        <a class="btn btn-default pull-right mgr5" href="<?php echo admin_page_url(RAOVAT_SLUG.'/them'); ?>"><i class="glyphicon glyphicon-plus"></i> Thêm mới</a>
        <a target="_blank" class="btn btn-success pull-right mgr5" href="<?php echo page_url(RAOVAT_SLUG.'/'.$oRaoVat->getSlug()); ?>"><i class="glyphicon glyphicon-search"></i> Xem</a>
        <?php } ?>
        <button type="button" class="btn btn-primary pull-right mgr5" onclick="wireOfAction('#btn-update', 'click');">
            <i class="glyphicon glyphicon-ok-sign"></i> <?php echo $screen_title; ?>
        </button>
    </div>
    <div class="clearfix"></div>

    <ol class="breadcrumb mgt5">
        <li><a href="<?php echo admin_page_url(); ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li><a href="<?php echo admin_page_url('rao-vat'); ?>"><i class="fa fa-table"></i> Rao vặt</a></li>
        <li class="active"><i class="fa fa-file"></i> <?php echo $oRaoVat->getTitle(); ?></li>
    </ol>
</div>

<form role="form" method="post" action="<?php echo $action_link; ?>" data-callback='1'>
    <div class="form-group col-md-2 col-xs-12">
        <?php if($oRaoVat->getImage()!=null) { ?>
        <a id="a-input-raovat-image" class="thumbnail fancybox" href="<?php echo raovat_upload($oRaoVat->getImage(), $oRaoVat->image_folder, false); ?>" title="<?php echo $oRaoVat->getTitle(); ?>">
            <img class="has-border" src="<?php echo raovat_upload($oRaoVat->getImage(), $oRaoVat->image_folder); ?>" />
        </a>
        <?php } else { ?>
        <a id="a-input-raovat-image" class="thumbnail fancybox" href="#" title="<?php echo $oRaoVat->getTitle(); ?>">
            <img class="has-border" data-src="holder.js/128x128/text:Hình đại diện" />
        </a>
        <?php } ?>
        <?php if($isOwner) { ?>
        <input type="hidden" class="form-control" id="input-raovat-image" name="raovat[image]" value="<?php echo $oRaoVat->getImage()!=null?RAOVAT_IMAGE_URL . $oRaoVat->getImage():''; ?>" />
        <button type="button" class="btn btn-success mgt5" id="btn-change-image" data-toggle="modal" data-target="#modal-change-image">
            <i class='glyphicon glyphicon-share-alt'></i> Thay đổi
        </button>
        <?php } ?>
    </div>
    <div class="form-group col-md-6 col-xs-12">
        <label for="input-raovat-title"><span class="text-danger">*</span> Tiêu đề</label>
        <?php $oRaoVat->setTitle($action=='insert'?'':$oRaoVat->getTitle()); ?>
        <input type="text" class="form-control auto-slug" follow-ctr='#input-raovat-slug' id="input-raovat-title" name="raovat[title]" value="<?php echo $oRaoVat->getTitle(); ?>" />
    </div>
    <div class="form-group col-md-6 col-xs-12">
        <label for="input-raovat-slug"><span class="text-danger">*</span> Đường dẫn</label>
        <input type="text" class="form-control" id="input-raovat-slug" name="raovat[slug]" value="<?php echo $oRaoVat->getSlug(); ?>"/>
    </div>
    <div class="clearfix"></div>

    <div class="form-group col-md-2 col-xs-3">
        <label>
            <input type="checkbox" name="raovat[active_flg]" value="1" <?php echo $oRaoVat->getActiveFlg()==1?"checked='checked'":""; ?> />&nbsp;Hiển thị
        </label>
    </div>
    <div class="form-group col-md-2 col-xs-3">
        <label>
            <input type="checkbox" name="raovat[delete_flg]" value="1" <?php echo $oRaoVat->getDeletedAt()!=NULL ?"checked='checked'":''; ?> />&nbsp;Xóa
        </label>
    </div>
    <div class="form-group col-md-8 col-xs-12">
        <label>
            <input type="checkbox" id="chk-custom-rao-vat-info" name="u[custom_info_flg]" value="1" <?php echo $oRaoVat->getCustomInfo()!=NULL ?"checked='checked'":''; ?> />&nbsp;
            Đăng cho người dùng không thuộc Phiên Chợ Việt
        </label>
    </div>
    <div class="clearfix"></div>

    <div class="col-md-6 col-xs-12 bg-warning" <?php echo $oRaoVat->getCustomInfo()!=NULL ?'':'style="display:none"'; ?> id="pn-custom-rao-vat-info">
        <div class="form-group">
            <label for="input-u-user"><span class="text-danger">*</span> Đăng bởi</label>
            <input type="text" class="form-control" id="input-u-user" name="u[user]" value="<?php echo $oRaoVat->user; ?>"/>
        </div>

        <div class='row'>
            <div class="col-md-6 col-xs-12">
                <div class="form-group">
                    <label for="input-u-company">Công ty</label>
                    <input type="text" class="form-control" id="input-u-company" name="u[company]" value="<?php echo $oRaoVat->company; ?>"/>
                </div>
                <div class="form-group">
                    <label for="input-u-address"><span class="text-danger">*</span> Địa chỉ</label>
                    <textarea class="form-control" id="input-u-address" name="u[address]" rows="4"><?php echo $oRaoVat->address; ?></textarea>
                </div>
            </div>
            <div class="col-md-6 col-xs-12">
                <div class="form-group">
                    <label for="input-u-phone"><span class="text-danger">*</span> Điện thoại</label>
                    <input type="text" class="form-control" id="input-u-phone" name="u[phone]" value="<?php echo $oRaoVat->phone; ?>"/>
                </div>
                <div class="form-group">
                    <!--<label for="input-u-email"><span class="text-danger">*</span> Email</label> !-->
                    <label for="input-u-email">Email</label>
                    <input type="text" class="form-control" id="input-u-email" name="u[email]" value="<?php echo $oRaoVat->email; ?>"/>
                </div>
                <div class="form-group">
                    <label for="input-u-skype">Skype</label>
                    <input type="text" class="form-control" id="input-u-skype" name="u[skype]" value="<?php echo $oRaoVat->skype; ?>"/>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-6 col-xs-12">
        <div class="form-group">
            <label for="input-raovat-place">Nơi áp dụng</label>
            <select class="form-control" id="input-raovat-place" name="raovat[place_id]">
                <?php foreach($aRaoVatPlace as $p) { ?>
                <option value="<?php echo $p->getId(); ?>" <?php echo $oRaoVat->getPlaceId()==$p->getId()?"selected='selected'":"";?> >
                    <?php echo $p->getName(); ?>
                </option>
                <?php } ?>
            </select>
        </div>
        <div class="form-group">
            <label for="input-raovat-category">Danh mục</label>
            <select class="form-control" id="input-raovat-category" name="raovat[cate_id]">
                <?php foreach($aRaoVatCate as $c) { ?>
                <option value="<?php echo $c->getId(); ?>" <?php echo $oRaoVat->getCateId()==$c->getId()?"selected='selected'":"";?> >
                    <?php echo $c->getTitle(); ?>
                </option>
                <?php } ?>
            </select>
        </div>
        <div class="form-group">
            <label for="input-raovat-order"><span class="text-danger">*</span> Giá / Mô tả</label>
            <textarea rows="4" class="form-control" id="input-raovat-description" name="raovat[description]"><?php echo $oRaoVat->getDescription(); ?></textarea>
        </div>
    </div>

    <div class="form-group col-md-12 col-xs-12 mgt10">
        <label for="input-raovat-detail"><span class="text-danger">*</span> Chi tiết</label>
        <textarea class="ckeditor" name="raovat_detail"><?php echo $oRaoVat->getDetail(); ?></textarea>
    </div>

    <div class="form-group col-md-12 col-xs-12">
        <?php if($action=='update') { ?>
        <input type="hidden" name="raovat[id]" value="<?php echo $this->encrypt->encode($oRaoVat->getId()); ?>" />
        <input type="hidden" name="raovat[update_case]" value="<?php echo UPDATE_FULL; ?>" />
        <?php } ?>
        <button type="button" class="btn btn-primary btn-submit-update" id="btn-update">
            <i class="glyphicon glyphicon-ok-sign"></i> <?php echo $screen_title; ?>
        </button>
        <button type="button" class="btn btn-default" onclick="back();">
            <i class="glyphicon glyphicon-share-alt"></i> Trở về
        </button>
    </div>
    <div class="clearfix"></div>
</form>

<?php if($isOwner) $this->load->view('backend/admin/image-modal/raovat.html.php'); ?>